package models

import (
	"time"
)

type Post struct {
	ID         uint      `json:"id" gorm:"primary_key"`
	Title      string    `json:"title" gorm:"not null"`
	Content    string    `json:"content" gorm:"type:text"`
	Summary    string    `json:"summary"`
	AuthorID   uint      `json:"author_id"`
	Author     User      `json:"author" gorm:"foreignkey:AuthorID"`
	CategoryID uint      `json:"category_id"`
	Category   Category  `json:"category,omitempty" gorm:"foreignkey:CategoryID"`
	Tags       string    `json:"tags"`
	Status     string    `json:"status" gorm:"default:'draft'"` // draft, published
	ViewCount  int       `json:"view_count" gorm:"default:0"`
	LikeCount  int       `json:"like_count" gorm:"default:0"`
	CreatedAt  time.Time `json:"created_at"`
	UpdatedAt  time.Time `json:"updated_at"`
	Comments   []Comment `json:"comments,omitempty" gorm:"foreignkey:PostID"`
}

type Category struct {
	ID          uint      `json:"id" gorm:"primary_key"`
	Name        string    `json:"name" gorm:"unique;not null"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
	Posts       []Post    `json:"posts,omitempty" gorm:"foreignkey:CategoryID"`
}
